package com.example.spidertp.core.controller;

import com.example.spidertp.common.ResponseEntity;
import com.example.spidertp.common.annotation.OperationAspect;
import com.example.spidertp.core.model.param.SpiderThreadPoolArgsParam;
import com.example.spidertp.core.model.vo.SpiderThreadPoolArgsVo;
import com.example.spidertp.core.model.vo.SpiderThreadPoolLivingStateVo;
import com.example.spidertp.core.service.ArgumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2022/9/17 4:44 下午
 */

@Api(tags = "线程池核心参数管理控制器")
@RequestMapping("/api/argument")
@RestController
public class ArgumentController {

    @Autowired
    private ArgumentService argumentService;

    @ApiOperation("获取线程池核心参数")
    @GetMapping("/info")
    public ResponseEntity<SpiderThreadPoolArgsVo> getThreadPollArgs(String name) {
        return ResponseEntity.ok(argumentService.getTreadPollArgs(name));
    }

    @ApiOperation("对线程池核心参数调参")
    @PostMapping("/adjust")
    @OperationAspect(accessPath = "/api/argument/adjust", accessDesc = "对线程池核心参数调参")
    public ResponseEntity<SpiderThreadPoolArgsVo> adjustPollArgs(@Validated @RequestBody SpiderThreadPoolArgsParam param) {
        return ResponseEntity.ok(argumentService.adjustPollArgs(param));
    }

    @ApiOperation("获取线程池生存状态")
    @GetMapping("/live")
    public ResponseEntity<SpiderThreadPoolLivingStateVo> getTreadPollLivingState(String name) {
        return ResponseEntity.ok(argumentService.getTreadPollLivingState(name));
    }

}
